const sharp = require('sharp');
const fs = require('fs');
const path = require('path');

async function generateFavicon() {
  try {
    // 读取 SVG 文件
    const svgBuffer = fs.readFileSync(path.join(__dirname, '../public/logo.svg'));
    
    // 转换为 PNG (32x32)
    const pngBuffer = await sharp(svgBuffer)
      .resize(32, 32)
      .png()
      .toBuffer();
    
    // 保存为 favicon.ico
    fs.writeFileSync(path.join(__dirname, '../public/favicon.ico'), pngBuffer);
    
    console.log('Favicon generated successfully!');
  } catch (error) {
    console.error('Error generating favicon:', error);
  }
}

generateFavicon(); 